*************************************************************************************
*************************************************************************************
*************************************************************************************
*
*		Replication Code for "A systematic approach to study electoral fraud"
*
*		L.Leemann & D. Bochsler, 2014
*		7/15/2015
*************************************************************************************
*************************************************************************************
*************************************************************************************

* set WD on your machine
cd "/Users/lleemann/Dropbox/benford/ecological approach/analysis/"

* read in data
use "Vote fraud data.dta", clear
set more off



****************
* TABLE 2
****************

reg emptyr_pest emptyr_pegr emptyr_pevv yesr_pegr yesr_pevv f entl_pe lostballots, robust
estimates store h3pe
reg emptyr_spst emptyr_spgr emptyr_spvv yesr_spgr yesr_spvv f entl_sp lostballots, robust
estimates store h3sp
reg emptyr_stst emptyr_stgr emptyr_stvv yesr_stgr yesr_stvv f entl_st lostballots, robust
estimates store h3st
reg emptyr_enst emptyr_engr emptyr_envv yesr_engr yesr_envv f entl_en lostballots, robust
estimates store h3en
reg emptyr_mfst emptyr_mfgr emptyr_mfvv yesr_mfgr yesr_mfvv f entl_mf lostballots, robust
estimates store h3mf

* OUTPUT
estout h3* , cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) style(tex) starlevels((*) 0.1 * 0.05 ** 0.01) stats(N r2)  replace


****************
* TABLE 3
****************


reg emptyr_mfgr emptyr_stgr emptyr_stvv emptyr_stst f entl_mf lostballots, robust
estimates store h4mfgr
reg emptyr_mfvv emptyr_stgr emptyr_stvv emptyr_stst f entl_mf lostballots, robust
estimates store h4mfvv
reg emptyr_mfst emptyr_stgr emptyr_stvv emptyr_stst f entl_mf lostballots, robust
estimates store h4mfst

* OUTPUT
estout h4mfgr h4mfvv h4mfst , replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) style(tex) starlevels((*) 0.1 * 0.05 ** 0.01) stats(N r2)


****************
* TABLE 4
****************


eq main: yesr_mfgr w_* mf_turnout lostballots entl_mf f
eq vare: lostballots entl_mf f
regh main vare , robust 
test [main]
test [vare]
predict pyesr_mfgr, xb
predict se_yesr_mfgr, stdp
gen p0yesr_mfgr = pyesr_mfgr + lostballots * 0.0121797
gen se0yesr_mfgr = se_yesr_mfgr - lostballots * 0.4918882


eq main: yesr_mfvv w_* mf_turnout lostballots entl_mf f
regh main vare , robust 
test [main]
test [vare]
predict pyesr_mfvv, xb
predict se_yesr_mfvv, stdp
gen p0yesr_mfvv = pyesr_mfvv - lostballots * .0083655 
gen se0yesr_mfvv = se_yesr_mfvv - lostballots * .1116017


eq main: yesr_mfst w_* mf_turnout lostballots entl_mf f
regh main vare , robust 
test [main]
test [vare]
predict pyesr_mfst, xb
predict se_yesr_mfst, stdp
gen p0yesr_mfst = pyesr_mfst + lostballots * .0114757
gen se0yesr_mfst = se_yesr_mfst - lostballots * .1171413 








****************
* APPENDIX: Table 6
****************

reg emptyr_spgr emptyr_pegr emptyr_pevv emptyr_pest f entl_sp, robust
estimates store h4spgr
predict pemptyr_spgr, xb
reg emptyr_spvv emptyr_pegr emptyr_pevv emptyr_pest f entl_sp, robust
estimates store h4spvv
predict pemptyr_spvv, xb
reg emptyr_spst emptyr_pegr emptyr_pevv emptyr_pest f entl_sp, robust
estimates store h4st
predict pemptyr_spst, xb


reg emptyr_stgr emptyr_spgr emptyr_spvv emptyr_spst f entl_st, robust
estimates store h4stgr
predict pemptyr_stgr, xb
reg emptyr_stvv emptyr_spgr emptyr_spvv emptyr_spst f entl_st, robust
estimates store h4stvv
predict pemptyr_stvv, xb
reg emptyr_stst emptyr_spgr emptyr_spvv emptyr_spst f entl_st, robust
estimates store h4stst
predict pemptyr_stst, xb


* OUTPUT
estout h4sp* h4st* 


****************
* APPENDIX - Table 7
****************


reg emptyr_mfgr emptyr_spgr emptyr_spvv emptyr_spst f entl_mf lostballots, robust
estimates store h4mfgr3
reg emptyr_mfvv emptyr_spgr emptyr_spvv emptyr_spst f entl_mf lostballots, robust
estimates store h4mfvv3
reg emptyr_mfst emptyr_spgr emptyr_spvv emptyr_spst f entl_mf lostballots, robust
estimates store h4mfst3

reg emptyr_mfgr emptyr_pegr emptyr_pevv emptyr_pest f entl_mf lostballots, robust
estimates store h4mfgr4
reg emptyr_mfvv emptyr_pegr emptyr_pevv emptyr_pest f entl_mf lostballots, robust
estimates store h4mfvv4
reg emptyr_mfst emptyr_pegr emptyr_pevv emptyr_pest f entl_mf lostballots, robust
estimates store h4mfst4

* OUTPUT
estout h4mfgr* h4mfvv* h4mfst*, replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) style(tex) starlevels((*) 0.1 * 0.05 ** 0.01) stats(N r2)
